﻿package core.ui.controls
{
    import core.event.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    public class TabBar extends Sprite
    {
        var bg:Sprite;
        var holder:Sprite;
        public var locked:Boolean;
        var selected:Tab;

        public function TabBar()
        {
            this.bg = new Sprite();
            this.bg.graphics.beginFill(13422292);
            this.bg.graphics.drawRect(0, 0, 100, 28);
            this.bg.graphics.beginFill(7171437);
            this.bg.graphics.drawRect(0, 0, 100, 27);
            var _loc_1:* = new Matrix();
            _loc_1.createGradientBox(100, 26, 90 / (180 / Math.PI), 0, 0);
            this.bg.graphics.beginGradientFill("linear", [8092539, 7171437], [1, 1], [0, 255], _loc_1);
            this.bg.graphics.drawRect(0, 1, 100, 26);
            this.bg.graphics.endFill();
            addChild(this.bg);
            this.holder = new Sprite();
            this.holder.y = -2;
            this.holder.x = 10;
            addChild(this.holder);
            return;
        }// end function

        public function Select(_arg1:String, _arg1:Boolean = false) : void
        {
            var _loc_3:int = 0;
            if (this.selected != null)
            {
                this.selected.Mark(false);
            }
            while (_loc_3 < this.holder.numChildren)
            {
                
                this.selected = this.holder.getChildAt(_loc_3) as Tab;
                if (this.selected.name == _arg1)
                {
                    break;
                }
                _loc_3++;
            }
            this.selected.Mark();
            if (_arg1)
            {
                dispatchEvent(new SelectEvent(SelectEvent.COMMAND, this.selected.name));
            }
            return;
        }// end function

        public function AddTab(_arg1:String, _arg1:BitmapData, _arg1:String, _arg1:Boolean = false) : void
        {
            var _loc_5:* = new Tab(_arg1, _arg1, _arg1);
            _loc_5.addEventListener(MouseEvent.CLICK, this.TabClick, false, 0, true);
            _loc_5.x = this.holder.width;
            this.holder.addChild(_loc_5);
            if (_arg1)
            {
                if (this.selected != null)
                {
                    this.selected.Mark(false);
                }
                this.selected = _loc_5;
                this.selected.Mark();
            }
            return;
        }// end function

        public function TabClick(event:MouseEvent) : void
        {
            if (!this.locked && event.currentTarget != this.selected)
            {
                if (this.selected != null)
                {
                    this.selected.Mark(false);
                }
                this.selected = event.currentTarget as Tab;
                this.selected.Mark();
                dispatchEvent(new SelectEvent(SelectEvent.COMMAND, this.selected.name));
            }
            return;
        }// end function

        public function Resize(_arg1:int) : void
        {
            this.bg.width = _arg1;
            return;
        }// end function

        public function get value() : String
        {
            return this.selected != null ? (this.selected.name) : ("");
        }// end function

    }
}
